import { NTag, NSpace, NButton, NPopconfirm } from 'naive-ui';
import Permisstion from '@/components/permission/index.vue';

export default function getColumns(
  openDialog: (row?: any) => void,
  handleDelete: (row: any) => Promise<void>,
) {
  return [
    {
      type: 'selection',
      width: 50,
      align: 'center',
    },
    {
      title: '岗位编号',
      key: 'postId',
      width: 160,
      ellipsis: { tooltip: true },
    },
    {
      title: '岗位编码',
      key: 'postCode',
    },
    {
      title: '岗位名称',
      key: 'postName',
    },
    {
      title: '岗位排序',
      key: 'postSort',
    },
    {
      title: '状态',
      key: 'status',
      width: 80,
      render: (row: any) => {
        const status = row.status === '0' ? 'success' : 'error';
        const label = row.status === '0' ? '正常' : '停用';
        return (
          <NTag type={status} size="small">
            {label}
          </NTag>
        );
      },
    },
    {
      title: '创建时间',
      key: 'createTime',
      width: 180,
    },
    {
      title: '操作',
      key: 'actions',
      width: 120,
      render: (row: any) => (
        <NSpace>
          <Permisstion hasPermi={['system:post:edit']}>
            <NButton text type="primary" size="tiny" onClick={() => openDialog(row)}>
              修改
            </NButton>
          </Permisstion>
          <Permisstion hasPermi={['system:post:remove']}>
            <NPopconfirm
              positiveText="确定"
              negativeText="取消"
              onPositiveClick={async () => {
                row.deleteLoading = true;
                await handleDelete([row]);
                row.deleteLoading = false;
              }}
              positiveButtonProps={{
                loading: row.deleteLoading,
              }}
              v-slots={{
                trigger: () => (
                  <NButton text type="error" size="tiny">
                    删除
                  </NButton>
                ),
              }}
            >
              确定删除{row.postName}吗？
            </NPopconfirm>
          </Permisstion>
        </NSpace>
      ),
    },
  ];
}
